#!/bin/sh
# postinst script for peerbox
#
# see: dh_installdeb(1)

conf() {
	echo "Configuring .currocoin directory for each user..."
	for _HOME in /home/*?; do
		# Obtain the username
		USER=$( basename ${_HOME} )

		if [ ! -d "$_HOME/.currocoin" ]; then
			echo "Currocoin directory not found for user $USER! Creating one now."
			mkdir $_HOME/.currocoin
		fi

		if [ ! -f $_HOME/.currocoin/currocoin.conf ]; then
			echo "Currocoin configuration file not found for user $USER! Creating one now."
			echo -e "rpcuser=rpcuser\nrpcpassword=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c10)" > $_HOME/.currocoin/currocoin.conf
		fi
		chown -R $USER: $_HOME/.currocoin
	done
}

set -e

case "$1" in
    configure)
	conf
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
